package example03;

import java.awt.*;
import javax.swing.*;
import net.sf.jeppers.grid.*;

/**
 * @author grom
 */
public class ComboGridDemo extends JFrame {	
	public ComboGridDemo() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        Object namedColors[] =
            {
                NamedColor.AQUA,
                NamedColor.BEIGE,
                NamedColor.BLACK,
                NamedColor.BLUE,
                NamedColor.EBLUE,
                NamedColor.JFCBLUE,
                NamedColor.JFCBLUE2,
                NamedColor.CYBERGREEN,
                NamedColor.DARKGREEN,
                NamedColor.FORESTGREEN,
                NamedColor.GRAY,
                NamedColor.GREEN,
                NamedColor.ORANGE,
                NamedColor.PURPLE,
                NamedColor.RED,
                NamedColor.RUSTRED,
                NamedColor.SUNPURPLE,
                NamedColor.SUSPECTPINK,
                NamedColor.TURQUOISE,
                NamedColor.VIOLET,
                NamedColor.YELLOW };
		
		JGrid grid = new JGrid(namedColors.length, 5);
		DefaultStyleModel styleModel = (DefaultStyleModel) grid.getStyleModel();
        styleModel.setRenderer(NamedColor.class, new NamedColorRenderer());
        JComboBox comboBox = new JComboBox(namedColors);		
		styleModel.setEditor(NamedColor.class, new GenericCellEditor(comboBox));
		
		// sample data
		for (int col = 1; col < grid.getColumnCount(); col++) {
			grid.setColumnWidth(col, 50);
			for (int row = 0; row < grid.getRowCount(); row++) {			
					grid.setValueAt("" + row + col, row, col);				
			}
		}
		for (int row = 0; row < grid.getRowCount(); row++) {
			grid.setValueAt(namedColors[row], row, 0);
		}
		
		grid.setColumnWidth(0, 130);
		
		JScrollPane scrollPane = new JScrollPane(grid);
		grid.setPreferredScrollableViewportSize(grid.getMaximumSize());
		getContentPane().add(scrollPane, BorderLayout.CENTER);
		
		pack();
	}
	
	public static void main(String[] args) {
	  ComboGridDemo sg = new ComboGridDemo();

	  Dimension big=Toolkit.getDefaultToolkit().getScreenSize();
	  Dimension small=sg.getSize();
	  sg.setLocation((big.width-small.width)/2,
					 (big.height-small.height)/2);

	  sg.setVisible(true);
	}	
}
